<template>
 <van-picker
    title="选择性别"
    show-toolbar
    :columns="columns"
    @confirm="submit"
    :default-index="gender"
    @cancel="$emit('close')"
  />
</template>

<script>
  import { updateUserProfile } from '@/api/user'
  export default {
    name:'EditGender',
    data() {
      return {
        columns: ['男','女']
      }
    },
    props:['gender'],
    methods: {
      async  submit(val,idx) {
        try {
          await updateUserProfile({
            gender:idx
          })
          this.$toast.success('更新成功')
          // 更新视图
          this.$emit('close',idx)
        } catch (error) {
          this.$toast.fail('更新失败')
        }
      }
    }
  }
</script>

<style lang="less" scoped>

</style>